package com.sqstudio.display.screen
{
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.EventDispatcher;

	/**
	 * 屏幕驱动器
	 * 记录美术界面规格原始信息，通知屏幕改变
	 * @author 翼翔天外
	 * 
	 */
	public class ScreenDriver extends EventDispatcher
	{
		/**
		 * 屏幕大小改变事件 
		 */
		public static const SCREEN_RESIZE:String = "screenResize";
		/**
		 * 单例引用 
		 */
		private static var _instance:ScreenDriver;
		
		private var _baseWidth:Number;
		private var _baseHeight:Number;
		public var stage:Stage;
	
		public function ScreenDriver(param:SingletonEnforcer)
		{
			
		}	
				
		/**
		 * 初始化 
		 * @param baseWidth
		 * @param baseHeight
		 * 
		 */
		public function init(baseWidth:Number,baseHeight:Number,stage:Stage):void
		{
			this._baseWidth = baseWidth;
			this._baseHeight = baseHeight;
			this.stage = stage;
			stage.addEventListener(Event.RESIZE,onStageResize);
		}
		
		/** 
		 * 发送屏幕改变事件
		 * 
		 */
		public function sendResizeEvent():void
		{
			this.dispatchEvent(new Event(SCREEN_RESIZE));
		}
		
		private function onStageResize(e:Event):void
		{
			sendResizeEvent();
		}
		
		/**
		 * 单例 
		 * @return 
		 * 
		 */
		public static function getInstance():ScreenDriver
		{
			if(_instance==null)
			{
				_instance = new ScreenDriver(new SingletonEnforcer());
			}
			return _instance;
		}

		/**
		 * 基准宽度 
		 */
		public function get baseWidth():Number
		{
			return _baseWidth;
		}
		
		/**
		 * 基准高度 
		 */
		public function get baseHeight():Number
		{
			return _baseHeight;
		}
		
		/**
		 * 当前宽度 
		 * @return 
		 * 
		 */
		public function get nowWidth():Number
		{
			return stage.stageWidth;
		}
		
		/**
		 * 当前高度 
		 * @return 
		 * 
		 */
		public function get nowHeight():Number
		{
			return stage.stageHeight;
		}

		
	}
}
class SingletonEnforcer{};